home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 23
/
AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso
/
Updates
/
HD-Installer
/
-WHDLoad-
/
WHDLoad_dev
/
Src
/
sources
/
savegame.s
< prev
next >
Wrap
Text File
|
1999-11-08
|
15KB
|
746 lines
;*---------------------------------------------------------------------------
; :Program. savegame.s
; :Contents. routine for multiple save game support
; it creates an interface from which the user can choice between
; 9 different savegames, a description can be entered for each
; savegame, all savegames will be stored in one single file which
; grows dynamically
; the savegames must have always the same size
; :Author. Wepl
; :Version. $Id: savegame.s 1.1 1998/06/27 23:53:54 jah Exp jah $
; :History. 14.06.98 extracted from Interphase slave
; 15.06.98 returncode fixed
; problem with savegames larger than $7fff fixed
; :Requires. _keyexit byte variable containing rawkey code
; _exit function to quit
; :Copyright. Public Domain
; :Language. 68000 Assembler
; :Translator. Barfly V2.9
; :To Do.
;---------------------------------------------------------------------------*
; this is a example sequence to use the savegame routine
; during execution some custom registers will be destroyed, if the installed
; program does not refresh them itself, it must be done after calling the
; savegame routine
IFEQ 1
move.l #100,d0 ;savegame size
lea $3e900,a0 ;address of savegame
lea $65000,a1 ;free mem for screen
bsr _sg_load
; move.w #$4100,(_custom+bplcon0)
; move.w #320/8*3,(_custom+bpl1mod)
; move.l #$00000eee,(_custom+color)
ENDC
;--------------------------------
; IN: d0 = ULONG size (only on function save required)
; a0 = APTR address of load/save area
; a1 = APTR space for the screen ($2800 bytes)
; OUT: d0 = BOOL success
; d1/a0/a1 destroyed
MAXNAMELEN = 40
LINE = 320/8
SCREEN = LINE*200
SAVEDIRLEN = 4+10+(10*MAXNAMELEN)
CHARHEIGHT = 5
CHARWIDTH = 5
INCLUDE macros/ntypes.i
NSTRUCTURE SaveGame,0
NLONG sg_screen
NLONG sg_size
NLONG sg_address
NLONG sg_old68
NLONG sg_old6c
NWORD sg_oldintena
NWORD sg_olddmacon
NSTRUCT sg_save_names,10*MAXNAMELEN
NSTRUCT sg_save_flags,10
NSTRUCT sg_save_id,4
NSTRUCT sg_tmpname,MAXNAMELEN
NWORD sg_c_x
NWORD sg_c_y
NBYTE sg_key
NBYTE sg_c_on
NBYTE sg_success
NALIGNLONG
NLABEL sg_SIZEOF
;--------------------------------
; print save game directory
; IN: -
; OUT: -
XBASE = 50
YBASE = 40
YSKIP = 15
_sg_printdir moveq #XBASE,d0 ;x-pos
moveq #YBASE-YSKIP,d1 ;first line
moveq #'1',d2
moveq #0,d3 ;amount saves
.next add.w #YSKIP,d1 ;line skip
bsr _pc
movem.l d0/d2,-(a7)
add.w #15,d0
sub.w #'1',d2
mulu.w #MAXNAMELEN,d2
lea (sg_save_names,a5),a0
add.w d2,a0
bsr _ps
movem.l (a7)+,d0/d2
addq.b #1,d2
cmp.b #'9',d2
bls .next
rts
;--------------------------------
; save a savegame
; IN: D0 = size of the savegame
; A0 = address to load savegame on
; A1 = address of free memory for screen ($2800 bytes)
; OUT: D0 = BOOL success
_sg_save moveq #0,d1
bra _sg_degrade
_sg_save_in bsr _sg_loaddir
.start moveq #7,d1
lea _save,a0
bsr _psc
add.w #8,d1
lea _saveselect,a0
bsr _psc
add.w #8,d1
lea _esc,a0
bsr _psc
bsr _sg_printdir
.keyloop bsr _sg_get_key
cmp.b #$45,d0
beq _sg_restore
lea (_keytrans),a0
move.b (a0,d0.w),d1
cmp.b #'1',d1
blo .keyloop
cmp.b #'9',d1
bhi .keyloop
moveq #XBASE+9,d0
sub.w #'1',d1
move.w d1,d6 ;D6 = save no.
mulu #YSKIP,d1
add.w #YBASE-5,d1
move.w d0,d2
add.w #210,d2
move.w d1,d3
add.w #YSKIP-1,d3
bsr _sg_rect
move.w d6,d0
mulu.w #MAXNAMELEN,d0
lea (sg_save_names,a5),a3
add.w d0,a3 ;A3 = save name
move.l a3,a0
lea (sg_tmpname,a5),a1
.cpy move.b (a0)+,(a1)+
bne .cpy
.chkname moveq #-1,d5
move.l a3,a0
.cnt addq.w #1,d5 ;D5 = charpos in save name
tst.b (a0)+
bne .cnt
move.w d5,d0
mulu #CHARWIDTH,d0
add.w #XBASE+15,d0
move.w d0,(sg_c_x,a5)
move.w d6,d1
mulu #YSKIP,d1
add.w #YBASE,d1
move.w d1,(sg_c_y,a5)
st (sg_c_on,a5)
moveq #15,d1
lea _saveinsert,a0
bsr _psc
.nextkey bsr _sg_get_key
cmp.b #$43,d0 ;enter
beq .return
cmp.b #$44,d0 ;return
beq .return
cmp.b #$41,d0 ;backspace
beq .bs
cmp.b #$46,d0 ;delete
beq .bs
cmp.b #$45,d0 ;escape
beq .esc
cmp.w #MAXNAMELEN-1,d5
beq .nextkey
lea (_keytrans),a0
move.b (a0,d0.w),d2
beq .nextkey
move.b d2,(a3,d5.w)
addq.w #1,d5
move.w (sg_c_x,a5),d0
move.w (sg_c_y,a5),d1
add.w #CHARWIDTH,(sg_c_x,a5)
bsr _pc
bra .nextkey
.bs tst.w d5
beq .nextkey
bsr _sg_cursoroff
subq.w #1,d5
clr.b (a3,d5.w)
bra .chkname
.esc bsr _sg_cursoroff
lea (sg_tmpname,a5),a0
move.l a3,a1
.cpy2 move.b (a0)+,(a1)+
bne .cpy2
bsr _sg_initscr
bra .start
.return tst.w d5 ;a name specified ?
beq .esc
bsr _sg_cursoroff
moveq #15,d1
lea _saveconfirm,a0
bsr _psc
.nextkey2 bsr _sg_get_key
cmp.b #$45,d0 ;escape
beq .esc
cmp.b #$43,d0 ;enter
beq .confirmed
cmp.b #$44,d0 ;return
bne .nextkey2
.confirmed lea (sg_save_flags,a5),a0
st (a0,d6.w)
move.l #SAVEDIRLEN,d0 ;size
moveq #0,d1 ;offset
lea (_sg_name),a0 ;filename
lea (sg_save_id,a5),a1 ;address
move.w #resload_SaveFileOffset,a2
bsr _sg_exec_resload
move.l (sg_size,a5),d0 ;size
move.l #SAVEDIRLEN,d1
bra .loopin
.loop add.l d0,d1 ;offset
.loopin subq.w #1,d6
bpl .loop
lea (_sg_name),a0 ;filename
move.l (sg_address,a5),a1 ;address
move.w #resload_SaveFileOffset,a2
bsr _sg_exec_resload
st (sg_success,a5)
bra _sg_restore
;--------------------------------
; disable text cursor
; IN: -
; OUT: -
_sg_cursoroff sf (sg_c_on,a5)
move.w (sg_c_x,a5),d0
move.w (sg_c_y,a5),d1
move.w #' ',d2
bra _pc
;--------------------------------
; clear screen
; IN: -
; OUT: -
_sg_clrscr movem.l d0/a0,-(a7)
move.l (sg_screen,a5),a0
move.w #(320*256/8)/4-1,d0
.clr clr.l (a0)+
dbf d0,.clr
movem.l (a7)+,d0/a0
rts
;--------------------------------
; init screen
; IN: -
; OUT: -
_sg_initscr movem.l d0-d3/a0,-(a7)
bsr _sg_clrscr
;draw border
; moveq #0,d0
; moveq #0,d1
; move.w #319,d2
; move.w #199,d3
; bsr _sg_rect
;print info
move.w #180,d1
lea _info1,a0
bsr _psc
add.w #8,d1
lea _info2,a0
bsr _psc
movem.l (a7)+,d0-d3/a0
rts
;--------------------------------
; load a savegame
; IN: A0 = address to load savegame on
; A1 = address of free memory for screen ($2800 bytes)
; OUT: D0 = BOOL success
_sg_load moveq #-1,d1
bra _sg_degrade
_sg_load_in bsr _sg_loaddir
beq .nosavegame
.start moveq #7,d1
lea _load,a0
bsr _psc
add.w #8,d1
lea _loadselect,a0
bsr _psc
add.w #8,d1
lea _esc,a0
bsr _psc
bsr _sg_printdir
lea (sg_save_names,a5),a0
moveq #0,d0
.keyloop bsr _sg_get_key
cmp.b #$45,d0
beq _sg_restore
lea (_keytrans),a0
moveq #0,d1
move.b (a0,d0.w),d1
cmp.b #'1',d1
blo .keyloop
cmp.b #'9',d1
bhi .keyloop
lea (sg_save_flags,a5),a0
tst.b (-'1',a0,d1.w)
beq .keyloop
moveq #XBASE+9,d0
sub.w #'1',d1
move.w d1,d6 ;D6 = save no.
mulu #YSKIP,d1
add.w #YBASE-5,d1
move.w d0,d2
add.w #210,d2
move.w d1,d3
add.w #YSKIP-1,d3
bsr _sg_rect
moveq #15,d1
lea _loadconfirm,a0
bsr _psc
.nextkey2 bsr _sg_get_key
cmp.b #$43,d0 ;enter
beq .confirmed
cmp.b #$44,d0 ;return
beq .confirmed
cmp.b #$45,d0 ;escape
bne .nextkey2
bsr _sg_initscr
bra .start
.confirmed move.l (sg_size,a5),d0 ;size
move.l #SAVEDIRLEN,d1
bra .loopin
.loop add.l d0,d1 ;offset
.loopin subq.w #1,d6
bpl .loop
lea (_sg_name),a0 ;filename
move.l (sg_address,a5),a1 ;address
move.w #resload_LoadFileOffset,a2
bsr _sg_exec_resload
st (sg_success,a5)
bra _sg_restore
.nosavegame moveq #60,d1
lea _loadno1,a0
bsr _psc
add.w #8,d1
lea _loadno2,a0
bsr _psc
bsr _sg_get_key
bra _sg_restore
;--------------------------------
; loads save directory
; IN: -
; OUT: D0 = BOOL success
; flags on D0
_sg_loaddir lea (_sg_name),a0
move.w #resload_GetFileSize,a2
bsr _sg_exec_resload
tst.l d0
beq .nocurrentfile
move.l #SAVEDIRLEN,d0 ;size
moveq #0,d1 ;offset
lea (_sg_name),a0 ;filename
lea (sg_save_id,a5),a1 ;address
move.w #resload_LoadFileOffset,a2
bsr _sg_exec_resload
cmp.l #"Wepl",(sg_save_id,a5)
bne .nocurrentfile
moveq #